﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace client
{
    public partial class FrmCmt : Form
    {
        Communicate cmt;

        public FrmCmt()
        {
            InitializeComponent();
            this.cmt = new Communicate();

        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Send_Click(object sender, EventArgs e)
        {
            string data;

            if (this.txt_CmtSend.Text.Trim() != "")
            {
                this.txt_CmtRecv.AppendText("管理员" + " " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() +
                                    "\r\n" + " " + this.txt_CmtSend.Text.Trim() + "\r\n");
                this.txt_CmtRecv.ScrollToCaret();
                data = this.txt_CmtSend.Text.Trim();
                this.txt_CmtSend.Text = "";
                //三台机器测试
                this.cmt.SendMSG(DateTime.Now, MsgLevel.LV_CMT, 1, data);           //1是Agent
                //两台机器测试
                //this.cmt.SendMSG(DateTime.Now, MsgLevel.LV_CMT, 1, data);
            }
            else
            {
                this.txt_CmtSend.Text = "";
            }

        }

        private void tim_CMT_Tick(object sender, EventArgs e)
        {
            DateTime time;
            MsgLevel lv;
            byte map;
            string data;
            bool isRecv;

            isRecv = this.cmt.RecvMSG(out time, out lv, out map, out data);
            if (isRecv == true)
            {
                this.Show();
                this.txt_CmtRecv.AppendText(Dns.GetHostName() + " " + time.ToShortDateString() + " " + time.ToShortTimeString() + "\r\n" + data + "\r\n");
                this.txt_CmtRecv.ScrollToCaret();
            }


        }
    }
}
